/*****************************************************************************
State of Aadhaar Survey 2017-2018

Title: 6_PDS_pub.do
Author: IDinsight
Contact: stateofaadhaar@idinsight.org
Date: 29 August 2018
Data: "SOA2018_nonroster_cleaned_gen.dta"
User-written commands: estout (ssc install estout if not installed)
Description: 	This .do file conducts analysis for the PDS section and
				produces output tables in "6_PDS.rtf".

Contents:
	
	1. Analysis using non roster data
		- Survey set up
		- Tabulations / Proportions / Means
		- Regressions / Hypothesis tests
	
Missing data code:
	.r = refused
	.d = don't know	
*****************************************************************************/

	
* Setting up
	
	version 14
	capture log close
	clear all
	mac drop _all
	set more off
	
	* Please replace "..." below with the correct file path on your computer
	if "`c(os)'"=="MacOSX"{
		global dir "/Users/`c(username)'/.../SOA2018_data_release/"
		}
	else{
		global dir "C:/Users/`c(username)'/.../SOA2018_data_release/"
		}

/*****************************************************************************
1. Analysis using non roster data
*****************************************************************************/

	*** Survey set up

		cd "${dir}/Data_sets/"
		use "SOA2018_nonroster_cleaned_gen.dta", clear

		drop hh_id
		rename master_key hh_id 
		svyset district_id [pweight=weight_hh_adj] || AC_id || ps_id || hh_id || _n
		cd "${dir}/Output_tables/"
		

	***  Tabulations / Proportions / Means
			
		/*****************************************************************************
		Proportion: Households with at least one ration card
		*****************************************************************************/
		
			eststo clear				
			eststo: estpost svy: tab rationcard_hh, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (rationcard_hh ==.d | rationcard_hh ==.r)
			estadd scalar missing  = r(N)
			count if (rationcard_hh ==.e) 
			estadd scalar er  = r(N)
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab rationcard_hh if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (rationcard_hh ==.d | rationcard_hh ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (rationcard_hh ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.1 Percentage of households with least one ration card") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"In West Bengal, ration cards are administered at an individual level. However, in Andhra Pradesh and Rajasthan ration cards are administered at the household level. For this analysis we aggregate responses at the household level for all states.") ///
				replace 
				
			eststo clear
			
			
		/*****************************************************************************
		Proportion: Type of ration card
		*****************************************************************************/
					
			* Andhra Pradesh
					
				eststo clear
				forvalues i = 1/1 {
					display `i' 	
					eststo: estpost svy: tab rctype if state == `i', percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (rctype ==.d | rctype ==.r) & state == `i'
					estadd scalar missing  = r(N)
					count if (rctype ==.e) & state == `i' 
					estadd scalar er  = r(N)	
					}
					
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					coeflabels(1 "Antyodaya (Yellow)" 2 "BPL (Red)" 3 "APL (Blue + White)" 4 "Annapurna" 5 "State BPL (Green)")	///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.2.1 Types of ration cards held by households (among households with at least one ration card; numbers in percentage) [State: Andhra Pradesh]") ///	
					nostar ///
					nonumbers ///
					mtitles ("Andhra Pradesh") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates.") ///
					append	
				eststo clear
			
				
			* Rajasthan
			
				eststo clear
				forvalues i = 2/2 {
					display `i' 	
					eststo: estpost svy: tab rctype if state == `i', percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (rctype ==.d | rctype ==.r) & state == `i'
					estadd scalar missing  = r(N)
					count if (rctype ==.e) & state == `i' 
					estadd scalar er  = r(N)	
					}
					
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					coeflabels(1 "Antyodaya (Yellow)" 2 "BPL (Red)" 3 "APL (Blue + White)" 4 "Annapurna" 5 "State BPL (Green)")	///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.2.2 Types of ration cards held by households (among households with at least one ration card; numbers in percentage) [State: Rajasthan]") ///	
					nostar ///
					nonumbers ///
					mtitles ("Rajasthan") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates.") ///
					append	
				eststo clear
			
			
			* West Bengal
			
				eststo clear
				forvalues i = 3/3 {
					display `i' 	
					eststo: estpost svy: tab rctype if state == `i', percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (rctype ==.d | rctype ==.r) & state == `i'
					estadd scalar missing  = r(N)
					count if (rctype ==.e) & state == `i' 
					estadd scalar er  = r(N)	
					}
					
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					coeflabels(1 "Antyodaya" 4 "Annapurna" 11 "Special Priority Household (S.P.H.H)" 12 "Priority Household (P.H.H)" 13 "Rajyo Khadyo Suraksha Yojona - I (R.K.S.Y - I)" 14 "Rajyo Khadyo Suraksha Yojona - II (R.K.S.Y - II)" 15 "Old Card (Not Digitised)" )	///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.2.3 Types of ration cards held by households (among households with at least one ration card; numbers in percentage) [State: West Bengal]") ///	
					nostar ///
					nonumbers ///
					mtitles ("West Bengal") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates.") ///
					append	
				eststo clear
			
		
		/*****************************************************************************
		Proportion: Number of times the household tried to collect ration  
		*****************************************************************************/
		
			eststo clear
				
			eststo: estpost svy: tab rcnumofvisits, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (rcnumofvisits ==.d | rcnumofvisits ==.r)
			estadd scalar missing  = r(N)
			count if (rcnumofvisits ==.e) 
			estadd scalar er  = r(N)
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab rcnumofvisits if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (rcnumofvisits ==.d | rcnumofvisits ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (rcnumofvisits ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.3 Number of times respondent households tried to collect ration in the last three months (among households with at least one ration card; numbers in percentage)") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates.")	///
				append 
				
			eststo clear
			
			
		/*****************************************************************************
		Proportion: System used at fair price shop   
		*****************************************************************************/
		
			eststo clear
			
			gen fpssystem_tab = fpssystem
			replace fpssystem_tab = 0 if fpssystem == 1
			replace fpssystem_tab = 1 if fpssystem == 2
			label values fpssystem_tab yesno 
				
			eststo: estpost svy: tab fpssystem_tab, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (fpssystem_tab ==.d | fpssystem_tab ==.r)
			estadd scalar missing  = r(N)
			count if (fpssystem_tab ==.e) 
			estadd scalar er  = r(N) 
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab fpssystem_tab if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (fpssystem_tab ==.d | fpssystem_tab ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (fpssystem_tab ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				coeflabels (1 "Register system" 2 "Aadhaar-based biometric authentication")	///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.4 Percentage of households that transact at a fair price shop that uses Aadhaar-based biometric authentication (among households with at least one ration card)") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"West Bengal has not adopted the Aadhaar-based system. In the two other states, households use either Aadhaar-based biometric authentication or the Register system. The former uses e-PoS devices for iris and/or fingerprint authentication for service delivery.")	/// 
				append 
				
			eststo clear			
			
			
		/*****************************************************************************
		Proportion: Amount of time taken to collect ration   
		*****************************************************************************/		
		
			eststo clear				
			eststo: estpost svy: tab rationtime, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (rationtime ==.d | rationtime ==.r)
			estadd scalar missing  = r(N)
			count if (rationtime ==.e) 
			estadd scalar er  = r(N) 
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab rationtime if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (rationtime ==.d | rationtime ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (rationtime ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.5 Average time taken to collect ration in the last three months (among households that tried to collect ration; numbers in percentage)") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"Respondents were asked 'What is the average time taken to collect ration in the last three months? (from the time of leaving from home and coming back)' and were given the options presented above to choose from. The smaller number of observations for Rajasthan is due to a high percentage of households not transacting even once in the last three months. We did not want to collect the data beyond a recall period of three months. Additionally, the questionnaire had an error that was corrected only after one week of surveying in Andhra Pradesh. The category '45 minutes-2 hours' was incorrectly labelled '45 minutes - 1 hour.'") ///
				append 
				
			eststo clear
			
			
		/*****************************************************************************
		Proportion: Number of attempts required for successful authentication 
		*****************************************************************************/
		
			eststo clear				
			eststo: estpost svy: tab rationlast3months_prop, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (rationlast3months_prop ==.d | rationlast3months_prop ==.r)
			estadd scalar missing  = r(N)
			count if (rationtime ==.e) 
			estadd scalar er  = r(N) 
			
			forvalues i = 1/2 {
				display `i' 
				eststo: estpost svy: tab rationlast3months_prop if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (rationlast3months_prop ==.d | rationlast3months_prop ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (rationlast3months_prop ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.6 Average number of attempts required for successful authentication using Aadhaar-based biometric authentication (among households that tried to collect ration and transact at a fair price shop that uses Aadhaar-based biometric authentication; numbers in percentage)") ///	
				nostar ///
				nonumbers ///
				mtitles ("Both states" "Andhra Pradesh" "Rajasthan") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"West Bengal is not included as they have not adopted the Aadhaar-based system. In the two other states, respondents were asked 'In the last three months, on average, how many times has it taken you (or another member of the household) for successful fingerprint authentication?' and were given the options presented above from which to choose. The smaller number of observations for Rajasthan is due to a high percentage of households not transacting even once in the last three months. We did not want to collect the data beyond a recall period of three months.") ///
				append 
				
			eststo clear
				
			
		/*****************************************************************************
		Proportion: Exclusion 
		*****************************************************************************/
		
			eststo clear		
			eststo: estpost svy: tab exclusion, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (exclusion ==.d | exclusion ==.r)
			estadd scalar missing  = r(N)
			count if (rationtime ==.e) 
			estadd scalar er  = r(N) 
			
			forvalues i = 1/3 {
				display `i' 
				eststo: estpost svy: tab exclusion if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (exclusion ==.d | exclusion ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (exclusion ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.7 Percentage of households excluded from PDS at least once in the last three months (among households with at least one ration card)") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"We define exclusion in PDS as cases where eligible beneficiary households are denied their food subsidy. In our survey, we asked respondents if they were ever unable to collect ration in the last three months and the reasons behind not collecting ration. We do not count exclusion in cases where the stated reason is not a case of `unfair denial', for instance the household members not being in the village for that particular month and collecting ration in the following month. Additionally, to ensure we capture all cases of exclusion, we count cases where individuals transacted less than three times in the last three months as denial (for West Bengal we used less than six times since rations are collected twice a month). The questionnaire was designed to capture exclusion for households that tried to transact at least once in the last three months. However, in Rajasthan we saw that a large number of respondents did not transact at all. Therefore we decided to adjust the questionnaire part way through the survey and to conduct follow up phone call surveys to check if these households had been excluded. The smaller number of observations for Rajasthan reflects cases where we were unable to reach the respondent via phone or if there was an error in data collection which equals to eighty four households.") ///
				append 
				
			eststo clear
			
			
		/*****************************************************************************
		Proportion: Monthly Exclusion Rate
		*****************************************************************************/
		
			eststo clear	
			eststo: svy: mean exclusion_times_weighted 
			count if (exclusion_times_weighted ==.d | exclusion_times_weighted ==.r) 
			estadd scalar missing  = r(N) 
			
			forvalues i = 1/3 {
				display `i' 
				eststo: svy: mean exclusion_times_weighted if state == `i'
				count if (exclusion_times_weighted ==.d | exclusion_times_weighted ==.r) & state == `i'
				estadd scalar missing  = r(N)
				}
				
			esttab using "6_PDS.rtf", ///
				compress ///
				eqlabels(none) ///
				label ///
				ci ///
				title ("Table 6.8 Average monthly exclusion rate in PDS for the last three months (among households with at least one ration card)") ///	
				nostar ///
				nonumbers ///
				b(3) ///
				mtitles ("All three states" "Andhra Pradesh (Aug - Dec'17)" "Rajasthan (Sep - Dec'17)" "West Bengal (Oct - Jan'18)") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"We estimate the average monthly exclusion rate in three steps: 1) for each respondent household that reported having been excluded from PDS in the last three months, we take the number of times they were excluded during this period to be the number of times they could have claimed ration but did not (i.e. three or six minus the number of times they successfully claimed ration); 2) we calculate the average number of times households were excluded from PDS each month by dividing the previous number by three (or six) for those who were ever excluded during this period, and assign a value of zero to households who were never excluded during this period; 3) we estimate the mean of the variable constructed in the previous step, applying household-level sampling weights. See footnote to Table 6.7 for a description of why there are fewer observations in Rajasthan.")	///
				append			
				
			eststo clear
			
				
		/*****************************************************************************
		Proportion: Aadhaar and Non Aadhaar Reasons
		*****************************************************************************/
		
			* Pooled
			
			eststo clear
			eststo: estpost svy: tab exclusionadnonadboth, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (exclusionadnonadboth ==.d | exclusionadnonadboth ==.r)
			estadd scalar missing  = r(N)
			count if (exclusionadnonadboth ==.e) 
			estadd scalar er  = r(N) 
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.9.1 Contribution of Aadhaar and Non Aadhaar-related factors to exclusion in PDS in the last three months (among households with at least one ration card; numbers in percentage) [All three states]") ///	
				nostar ///
				nonumbers ///
				mtitles ("All three states") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"The observations in the table above are about the three month period leading up to the survey Aadhaar-related reasons include: Aadhaar seeding, Aadhaar authentication failures, non-availability of PoS-able member, and e-PoS connectivity/electricity issues. Non Aadhaar-related reasons include: Non-availability of ration and other reasons such as dealer not being present. Since this is the calculated average for three months, it is possible that a household was excluded in one month due to an Aadhaar-related reason and in another due to a Non Aadhaar-related reason. Such cases are classified as 'Both.' See footnote to Table 6.7 for a description of why there are fewer observations in Rajasthan.") ///	
				append
			
			
			* By state
			
				* Andhra Pradesh			
				eststo clear 
					eststo: estpost svy: tab exclusionadnonadboth if state == 1, percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (exclusionadnonadboth ==.d | exclusionadnonadboth ==.r) & state == 1
					estadd scalar missing  = r(N)
					count if (exclusionadnonadboth ==.e) & state == 1
					estadd scalar er  = r(N)
				
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					label ///
					modelwidth(0) ///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.9.2 Contribution of Aadhaar and Non Aadhaar-related factors to exclusion in PDS in the last three months (among households with at least one ration card; numbers in percentage) [State: Andhra Pradesh]") ///	
					nostar ///
					nonumbers ///
					mtitles ("Andhra Pradesh") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates."	///
					"See footnote to Table 6.9.1 for definitions of various types of errors.")	///
					append
					
				eststo clear
				
				
				* Rajasthan			
				eststo clear 
					eststo: estpost svy: tab exclusionadnonadboth if state == 2, percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (exclusionadnonadboth ==.d | exclusionadnonadboth ==.r) & state == 2
					estadd scalar missing  = r(N)
					count if (exclusionadnonadboth ==.e) & state == 2
					estadd scalar er  = r(N)
				
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					label ///
					modelwidth(0) ///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.9.3 Contribution of Aadhaar and Non Aadhaar-related factors to exclusion in PDS in the last three months (among households with at least one ration card; numbers in percentage) [State: Rajasthan]") ///	
					nostar ///
					nonumbers ///
					mtitles ("Rajasthan") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates."	///
					"See footnote to Table 6.9.1 for definitions of various types of errors. See footnote to Table 6.7 for a description of why there are fewer observations in Rajasthan.")	///
					append
					
				eststo clear
				
				* West Bengal				
				eststo clear 
					eststo: estpost svy: tab exclusionadnonadboth if state == 3, percent nototal ci
					estadd matrix cil = e(lb)
					estadd matrix ciu = e(ub)
					count if (exclusionadnonadboth ==.d | exclusionadnonadboth ==.r) & state == 3
					estadd scalar missing  = r(N)
					count if (exclusionadnonadboth ==.e) & state == 3
					estadd scalar er  = r(N)
				
				esttab using "6_PDS.rtf", ///
					compress ///
					collabels(none) ///
					eqlabels(none) ///
					label ///
					modelwidth(0) ///
					incelldelimiter(-) ///
					cells(b(fmt(1)) "cil & ciu") ///
					title ("Table 6.9.4 Contribution of Aadhaar and Non Aadhaar-related factors to exclusion in PDS in the last three months (among households with at least one ration card; numbers in percentage) [State: West Bengal]") ///	
					nostar ///
					nonumbers ///
					mtitles ("West Bengal") ///
					nogaps ///
					stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (refused)")) ///
					nonotes ///
					addnotes("Notes: 95% confidence intervals are under point estimates."	///
					"See footnote to Table 6.9.1 for definitions of various types of errors.")	///
					append
					
				eststo clear
				
					
		/*****************************************************************************
		Proportion: Reasons for exclusion Overall 
		*****************************************************************************/
			
			eststo clear	
			
			* Pooled
			
			foreach var of varlist exclusion_bucket_? exclusion_bucket_?? {	
				eststo: estpost svy: tab `var', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r)
				estadd scalar missing  = r(N)
				count if (`var' ==.e)
				estadd scalar er  = r(N)
				}
				
			local k = `i' + 1 
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.10.1 Reasons for exclusion from PDS in the last three months (among households that have been excluded; numbers in percentage) [All three states]") ///
				nostar ///
				nonumbers ///
				mtitles ("No ration available" "Aadhaar seeding" "Aadhaar authentication failures" "Connectivity/electricity issues" "No PoS-able member available" "Other" "Don't know") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"The observations in the table above are about the three month period leading up to the survey.") ///
				append 
			
			* By state
			
			eststo clear	
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			forv i = 1/3{
			foreach var of varlist exclusion_bucket_? exclusion_bucket_?? {	
				display `i' 
				eststo: estpost svy: tab `var' if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			local k = `i' + 1 
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.10.`k' Reasons for exclusion from PDS in the last three months (among households that have been excluded; numbers in percentage) [State: ``i++'']") ///
				nostar ///
				nonumbers ///
				mtitles ("No ration available" "Aadhaar seeding" "Aadhaar authentication failures" "Connectivity/electricity issues" "No PoS-able member available" "Other" "Don't know") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"The observations in the table above are about the three month period leading up to the survey.") ///
				append 
				
			eststo clear	
			}
			
			
		/*****************************************************************************
		Q13. Comparing the system with which you receive your rations now using Aadhaar vs. the system with how you received it before without Aadhaar, what is your opinion about the new system?
		* Types of analysis: Proportion  systemcompare
		*****************************************************************************/
		
			eststo clear			
			eststo: estpost svy: tab systemcompare, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (systemcompare ==.d | systemcompare ==.r)
			estadd scalar missing  = r(N)
			count if (systemcompare ==.e) 
			estadd scalar er  = r(N) 
			
			forvalues i = 1/2 {
				display `i' 
				eststo: estpost svy: tab systemcompare if state == `i', percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (systemcompare ==.d | systemcompare ==.r) & state == `i'
				estadd scalar missing  = r(N)
				count if (systemcompare ==.e) & state == `i'
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				label ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.11 Whether respondent thinks the Aadhaar-enabled PDS system is better or worse than the previous system (among those who have used the Aadhaar-based system; numbers in percentage)") ///	
				nostar ///
				nonumbers ///
				mtitles ("Both states" "Andhra Pradesh" "Rajasthan") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"West Bengal has not adopted the Aadhaar-based system. The smaller number of observations for Rajasthan reflects cases where individuals said that their fair price shop uses the Aadhaar-based system but they had not transacted at the shop."	///
				"Respondents were asked 'Comparing the system with which you receive your rations now using Aadhaar vs. the system with how you received it before without Aadhaar, what is your opinion about the new system?' and were given the following options to choose from: 'Better', 'Same' and 'Worse' to choose from.") ///
				append 
				
			eststo clear	
		
		
		/*****************************************************************************
		Q14. Why do you find the new system better?
		* Types of analysis: Proportion  exclusion
		*****************************************************************************/
		
			eststo clear	
			
			* Pooled
			
			foreach var of varlist systembetterhow_? {	
				eststo: estpost svy: tab `var' if (state == 1 | state == 2), percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & (state == 1 | state == 2)
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & (state == 1 | state == 2)
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.12.1 Reasons for thinking the Aadhaar enabled PDS system is better (among respondents who think it is better; numbers in percentage) [States: Andhra Pradesh and Rajasthan]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (shopkeeper etc. cannot keep it)" "We get our ration now (didn't get it before)" "We always get ration now (irregular before)" "We get the complete quota of ration" "We have to do less visits per month to get ration" "We have to spend less time at the PDS shop to get ration"  "We face less technical issues (machine, electricity, internet, fingerprint failures etc.)" "We face less non-technical issues" "We pay the stipulated amount for ration now") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"West Bengal has not adopted the Aadhaar-based system. The smaller number of observations for Rajasthan reflects cases where individuals said that their fair price shop uses the Aadhaar-based system but had not transacted at the shop.")	///
				append
			
			* By state
			
			eststo clear	
			foreach var of varlist systembetterhow_? {	
				eststo: estpost svy: tab `var' if state == 1, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & state == 1
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & state == 1
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.12.2 Reasons for thinking the Aadhaar enabled PDS system is better (among respondents who think it is better; numbers in percentage) [State: Andhra Pradesh]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (shopkeeper etc. cannot keep it)" "We get our ration now (didn't get it before)" "We always get ration now (irregular before)" "We get the complete quota of ration" "We have to do less visits per month to get ration" "We have to spend less time at the PDS shop to get ration"  "We face less technical issues (machine, electricity, internet, fingerprint failures etc.)" "We face less non-technical issues" "We pay the stipulated amount for ration now") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"This question was not part of our original survey in Andhra Pradesh and was only added after we had completed half of our survey. We conducted a phone survey on this question to the first half of respondents in Andhra Pradesh. The smaller number of observations reflects cases where we were unable to reach the respondent via phone whcih equals to one hundred and eighteen households.") ///
				append 
				
				
			eststo clear	
			local systembetter1 systembetterhow_1 systembetterhow_2 systembetterhow_3 systembetterhow_4 systembetterhow_5 systembetterhow_6 systembetterhow_7 systembetterhow_8 	
			
			foreach var of varlist systembetterhow_? {	
				display `i' 
				eststo: estpost svy: tab `var' if state == 2, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & state == 2
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & state == 2
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.12.3 Reasons for thinking the Aadhaar enabled PDS system is better (among respondents who think it is better; numbers in percentage) [State: Rajasthan]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (shopkeeper etc. cannot keep it)" "We get our ration now (didn't get it before)" "We always get ration now (irregular before)" "We get the complete quota of ration" "We have to do less visits per month to get ration" "We have to spend less time at the PDS shop to get ration"  "We face less technical issues (machine, electricity, internet, fingerprint failures etc.)" "We face less non-technical issues") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Note: 95% confidence intervals are under point estimates.") ///
				append 
			
				
		/*****************************************************************************
		Q15. Why do you find the new system worse?
		* Types of analysis: Proportion  exclusion
		*****************************************************************************/
		
			eststo clear	
			
			* Pooled
			
			foreach var of varlist systemworsehow_? {	
				eststo: estpost svy: tab `var' if (state == 1 | state == 2), percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & (state == 1 | state == 2)
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & (state == 1 | state == 2)
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.13.1 Reasons for thinking the Aadhaar enabled PDS system is worse (among respondents who think it is worse; numbers in percentage) [State: Andhra Pradesh and Rajasthan]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (shopkeeper etc. cannot keep it)" "We get our ration now (didn't get it before)" "We always get ration now (irregular before)" "We get the complete quota of ration" "We have to do less visits per month to get ration" "We have to spend less time at the PDS shop to get ration"  "We face less technical issues (machine, electricity, internet, fingerprint failures etc.)" "We face less non-technical issues" "We pay the stipulated amount for ration now") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"West Bengal has not adopted the Aadhaar-based system. The smaller number of observations for Rajasthan reflects cases where individuals said that their fair price shop uses the Aadhaar-based system but had not transacted at the shop.")	///
				append
			
			* By state
			
			eststo clear		
			foreach var of varlist systemworsehow_? {	
				eststo: estpost svy: tab `var' if state == 1, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & state == 1
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & state == 1
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.13.2 Reasons for thinking the Aadhaar enabled PDS system is worse (among respondents who think it is worse; numbers in percentage) [State: Andhra Pradesh]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (cannot send our children/siblings etc. to fetch our ration)" "We don't get ration any more" "We don't get ration sometimes" "We get less than the right ration quota" "We have to do more visits per month to get ration" "We have to spend more time at the PDS shop to get ration"  "We face more technical issues" "We face more non-technical issues"  "We pay more than the stipluated amount for ration now (or pay more money now)") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Notes: 95% confidence intervals are under point estimates."	///
				"This question was not part of our original survey in Andhra Pradesh and was only added after we had completed half of our survey. We conducted a phone survey on this question to the first half of respondents in Andhra Pradesh. The smaller number of observations reflects cases where we were unable to reach the respondent via phone which equals to 68 households.") ///
				append 
								
			eststo clear	
			
			foreach var of varlist systemworsehow_? {	
				display `i' 
				eststo: estpost svy: tab `var' if state == 2, percent nototal ci
				estadd matrix cil = e(lb)
				estadd matrix ciu = e(ub)
				count if (`var' ==.d | `var' ==.r) & state == 2
				estadd scalar missing  = r(N)
				count if (`var' ==.e) & state == 2
				estadd scalar er  = r(N)
					}
			
			esttab using "6_PDS.rtf", ///
				compress ///
				collabels(none) ///
				eqlabels(none) ///
				modelwidth(0) ///
				incelldelimiter(-) ///
				cells(b(fmt(1)) "cil & ciu") ///
				title ("Table 6.13.3 Reasons for thinking the Aadhaar enabled PDS system is worse (among respondents who think it is worse; numbers in percentage) [State: Rajasthan]") ///	
				nostar ///
				nonumbers ///
				mtitles ("No one else can take our ration now (cannot send our children/siblings etc. to fetch our ration)" "We don't get ration any more" "We don't get ration sometimes" "We get less than the right ration quota" "We have to do more visits per month to get ration" "We have to spend more time at the PDS shop to get ration"  "We face more technical issues" "We face more non-technical issues"  "We pay more than the stipluated amount for ration now (or pay more money now)") ///
				nogaps ///
				stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
				nonotes ///
				addnotes("Note: 95% confidence intervals are under point estimates.") ///
				append 


	***  Regressions / Hypothesis tests
	
		************************************************************************************	
		** Number of authentication attempts **	
		************************************************************************************	
		
			* Pooled
			
			eststo clear
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim majority_female_HH maxedu_noschool"'
				
				local j = 1
				foreach var in `regressors'{
					qui svy: regress rationlast3months `var' 
					gen sample = e(sample)
					count if (rationlast3months ==.d | rationlast3months ==.r) 
					loc miss = r(N)
					count if (rationlast3months ==.e)
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean rationlast3months
					loc y1 = _b[rationlast3months]
					eststo: svy: regress rationlast3months `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.14.1 Hypothesis tests of differences in number of attempts required for successful authentication among households from different vulnerable communities [States: Andhra Pradesh and Rajasthan])") ///	
					coeflabels (sc_cat "SC household" st_cat "ST household" rel_muslim "Muslim household" maxedu_noschool "No household member has gone to school" majority_female_HH "Households with majority female adults") ///
					mtitles ("Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" ) ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"West Bengal has not adopted the Aadhaar-based system. We test the null hypotheses that there are no differences in the number of times needed to successfully authenticate between vulnerable households and other households, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each household type above has a different average number of attempts needed compared to all other households (i.e. all those not in the specified type).") ///
					`option'
					loc option append		
			eststo clear	
			
			
			
			* By state
			eststo clear
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/2{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim majority_female_HH maxedu_noschool"'
				
				local j = 1
				foreach var in `regressors'{
					qui svy: regress rationlast3months `var' if state == `i'
					gen sample = e(sample)
					count if (rationlast3months ==.d | rationlast3months ==.r) & state == `i'
					loc miss = r(N)
					count if (rationlast3months ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean rationlast3months
					loc y1 = _b[rationlast3months]
					eststo: svy: regress rationlast3months `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			local k = `i' + 1 	
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.14.`k' Hypothesis tests of differences in number of attempts required for successful authentication among households from different vulnerable communities [State: ``i++'']") ///	
					coeflabels (sc_cat "SC household" st_cat "ST household" rel_muslim "Muslim household" maxedu_noschool "No household member has gone to school" majority_female_HH "Households with majority female adults") ///
					mtitles ("Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" "Number of authentication attempts" ) ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 6.14.1 for a description of the hypotheses tested here.")	///
					`option'
					loc option append
			}		
			eststo clear	
			
			
		************************************************************************************	
		** Monnthly exclusion rate **
		************************************************************************************	
			
			* Pooled
			
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim majority_female_HH maxedu_noschool"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress exclusion_times_weighted `var'
					gen sample = e(sample)
					count if (exclusion_times_weighted ==.d | exclusion_times_weighted ==.r) 
					loc miss = r(N)
					count if (exclusion_times_weighted ==.e) 
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean exclusion_times_weighted
					loc y1 = _b[exclusion_times_weighted]
					eststo: svy: regress exclusion_times_weighted `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.15.1 Hypothesis tests of differences in monthly exclusion rate among households from different vulnerable communities [All three states]") ///	
					coeflabels (sc_cat "SC household" st_cat "ST household" rel_muslim "Muslim household" maxedu_noschool "No household member has gone to school" majority_female_HH "Households with majority female adults") ///
					mtitles ("Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"We test the null hypotheses that there are no differences in the monthly exclusion rates between vulnerable households and other households, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each household type above has a different monthly exclusion rate compared to all other households (i.e. all those not in the specified type).") ///
					`option'
					loc option append
			eststo clear	
			
			
			* By state
			
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/3{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim majority_female_HH maxedu_noschool"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress exclusion_times_weighted `var' if state == `i'
					gen sample = e(sample)
					count if (exclusion_times_weighted ==.d | exclusion_times_weighted ==.r) & state == `i'
					loc miss = r(N)
					count if (exclusion_times_weighted ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean exclusion_times_weighted
					loc y1 = _b[exclusion_times_weighted]
					eststo: svy: regress exclusion_times_weighted `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			local k = `i' + 1 	
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.15.`k' Hypothesis tests of differences in monthly exclusion rate among households from different vulnerable communities [State: ``i++'']") ///	
					coeflabels (sc_cat "SC household" st_cat "ST household" rel_muslim "Muslim household" maxedu_noschool "No household member has gone to school" majority_female_HH "Households with majority female adults") ///
					mtitles ("Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS" "Monthly exclusion rate in PDS") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 6.15.1 for a description of the hypotheses tested here.")	///
					`option'
					loc option append
			}		
			eststo clear	

			
		************************************************************************************	
		** Approval rating **
		************************************************************************************
		
			* switching back to respondent weights since it's the opinion of respondents
			svyset district_id [pweight=weight_resp_adj] || AC_id || ps_id || hh_id || _n
			
			
			replace systemcompare =.d if systemcompare == 4
			recode systemcompare (5 = 1) (2 = 3) (3 = 2)
			label define systemcompare1 1 "Worse" 2 "Neutral" 3 "Better"
			label values systemcompare systemcompare1
			
			* Pooled
			
			loc option append
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress systemcompare `var' 
					gen sample = e(sample)
					count if (systemcompare ==.d | systemcompare ==.r) 
					loc miss = r(N)
					count if (systemcompare ==.e) 
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean systemcompare
					loc y1 = _b[systemcompare]
					eststo: svy: regress systemcompare `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.16.1 Hypothesis tests of differences in respondents' view on the Aadhaar enabled PDS system relative to the previous system among respondents from different vulnerable communities [States: Andhra Pradesh and Rajasthan]") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"West Bengal has not adopted the Aadhaar-based system. We test the null hypotheses that there are no differences in the view on the new system compared to the old system between vulnerable respondents and other respondents, with vulnerability being proxied by each of the categories above. Each column presents coefficients from a regression of the outcome variable on a dummy variable for the corresponding category and a constant. Hence we separately examine whether each respondent type above has a different view on the new system compared to the old system compared to all other households (i.e. all those not in the specified type).") ///
					`option'
					loc option append
			eststo clear	
			
			* By state
			
			tokenize `" "Andhra Pradesh" "Rajasthan" "West Bengal" "'
			loc option append
			forv i = 1/2{
				eststo clear
				local regressors `" "sc_cat st_cat" rel_muslim resp_female resp_noschool resp_above60"'
				local j = 1
				foreach var in `regressors'{
					qui svy: regress systemcompare `var' if state == `i'
					gen sample = e(sample)
					count if (systemcompare ==.d | systemcompare ==.r) & state == `i'
					loc miss = r(N)
					count if (systemcompare ==.e) & state == `i'
					loc errors = r(N)
					
					preserve
					keep if sample == 1
					svy: mean `var'
					if `j++'==1{
						loc x1 = _b[sc_cat] 
						loc x2 = _b[st_cat]
					}
					else{
						loc x1 = _b[`var']
						loc x2 = .
					}
					svy: mean systemcompare
					loc y1 = _b[systemcompare]
					eststo: svy: regress systemcompare `var'
					estadd scalar missing = `miss'
					estadd scalar errors = `errors'
					estadd scalar y = `y1'
					estadd scalar x = `x1'
					estadd scalar z = `x2'
					restore
					drop sample
				}
			local k = `i' + 1 	
			esttab using "6_PDS.rtf", ///
					compress ///
					eqlabels(none) ///
					label ///
					title ("Table 6.16.`k' Hypothesis tests of differences in respondents' view on the Aadhaar enabled PDS system relative to the old one among respondents from different vulnerable communities [State: ``i++'']") ///	
					coeflabels (sc_cat "SC respondent" st_cat "ST respondent" rel_muslim "Muslim respondent" resp_noschool  "Respondent has not attended school" resp_female "Female respondent" resp_above60 "Respondent above age 60") ///
					mtitles ("View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old" "View of new system compared to old") ///
					p ///
					star (* 0.1 ** 0.05 *** 0.01) ///
					lines ///
					b (3) ///
					p (2) ///
					nogaps ///
					stats(N r2 y, fmt(0 3 3) label("Number of observations" "R-squared" "Mean of dependent variable")) ///	
					nonotes ///
					addnotes("Notes: p-values in parentheses, with ***, **, * indicating significance at 1, 5 and 10%. No correction for multiple hypothesis testing has been applied to the results in the table." ///
					"See footnote to Table 6.16.1 for a description of the hypotheses tested here.")	///
					`option'
					loc option append
			}		
			eststo clear	
